import React, { useState, useEffect } from 'react'
function getRandomIntInclusive(min, max) {
  min = Math.ceil(min)
  max = Math.floor(max)
  return Math.floor(Math.random() * (max - min + 1)) + min //含最大值，含最小值
}
// useEffect 只模拟了componentDidMount, componentDidUpdate, componentWillUnmount
export default function Count() {
  const [count, setCount] = useState(9)

  // 外部的回调.模拟的是挂载和更新
  useEffect(() => {
    console.log('count挂载或更新了')
    // 内部的这个回调,模拟的是卸载
    return () => {
      console.log('count卸载了')
    }
  }, [count])

  

  return (
    <div>
      Count
      <hr />
      <p>{count}</p>
      <button
        onClick={() => {
          setCount(getRandomIntInclusive(1, 2))
        }}
      >
        +
      </button>
    </div>
  )
}
